package com.notetool.util;

import java.util.HashMap;

import com.notetool.util.tokenparser.Parser;
import com.notetool.util.tokenparser.semantic.MatchingTokensRestriction;
import com.notetool.util.tokenparser.semantic.NeighborTokenRestriction;
import com.notetool.util.tokenparser.syntax.SingleCharModel;
import com.notetool.util.tokenparser.syntax.WordModel;

public class ParsingHelper
{
    
    public static Parser getTestParser ()
    {
        ////
        //Test singlechartoken options... invisible/group/deny, etc
        ////
        ////
        ////
        //// .regroup ().unique ()
        //// remove the 3rd step where we purge the invisible and remove the invisible indicator.
        //// Add a purge ("class") and purge(Model) to TokenList
        
        
        
        
        
        Parser parser = new Parser ();
        
        SingleCharModel charSpace  = new SingleCharModel (' ').addClass ("whiteSpace").grouped ();
        SingleCharModel charTab    = new SingleCharModel ('\t').addClass ("whiteSpace");
        SingleCharModel charParenO = new SingleCharModel ('(').addClass ("control", "grouping", "groupingOpening");
        SingleCharModel charParenC = new SingleCharModel (')').addClass ("control", "grouping", "groupingClosing");
        SingleCharModel charUnion  = new SingleCharModel ('|').addClass ("control", "operator", "operatorUnion");
        SingleCharModel charInter  = new SingleCharModel ('&').addClass ("control", "operator", "operatorIntersect");
        SingleCharModel charId     = new SingleCharModel ('@').addClass ("control", "id");
        
        WordModel tag = new WordModel (".*").addClass ("tagWord");
        WordModel id = new WordModel (".*").addClass ("idWord");
        
        NeighborTokenRestriction restriction;
        
        // ( restrictions
        restriction = new NeighborTokenRestriction ();
        restriction.addIgnored ("whiteSpace");
        restriction.addRequiredNext (charParenO, charId, tag);
        
        charParenO.addRestriction(restriction);
        
        // ) restrictions
        restriction = new NeighborTokenRestriction ();
        restriction.addIgnored ("whiteSpace");
        restriction.addRequiredPrevious (charParenC, tag, id);
        
        charParenC.addRestriction(restriction);
        
        // |
        restriction = new NeighborTokenRestriction ();
        restriction.addIgnored ("whiteSpace");
        restriction.addRequiredNext (charParenO, charId, tag);
        restriction.addRequiredPrevious (charParenC, tag, id);
        
        charUnion.addRestriction(restriction);
        
        // &
        
        restriction = new NeighborTokenRestriction ();
        restriction.addIgnored ("whiteSpace");
        restriction.addRequiredNext (charParenO, charId, tag);
        restriction.addRequiredPrevious (charParenC, tag, id);
        
        charInter.addRestriction(restriction);
        
        // @
        restriction = new NeighborTokenRestriction ();
        restriction.addRequiredNext (id);
        
        charId.addRestriction(restriction);
        
        charId.addPreferedNext (id);
        
        // tag
        restriction = new NeighborTokenRestriction ();
        restriction.addIgnored ("whiteSpace");
        restriction.addRequiredNext (charUnion, charInter, charParenC, null);
        restriction.addRequiredPrevious (charUnion, charInter, charParenO, null);
        
        tag.addRestriction(restriction);
        
        // id
        restriction = new NeighborTokenRestriction ();
        restriction.addIgnored ("whiteSpace");
        restriction.addRequiredNext (charUnion, charInter, charParenC, null);
        restriction.addRequiredPrevious (charId);
        
        id.addRestriction(restriction);
        
        parser.addSingleCharModel(charSpace, charTab, charParenO, charParenC, charInter, charUnion, charId);
        parser.addWordModel (tag, id);
        
        parser.addRestriction(new MatchingTokensRestriction (charParenO, charParenC));
        
        return parser;
        
        // Add Model class... Just a string that represents the "class" of the Token
        // Make it so TokenRestriction's take tokens AND also classes...
        // Add ignored classes/tokens
    }

}
